package me.jessyan.mvparms.demo.mvp.ui.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.PagerAdapter;
import android.support.v7.widget.LinearLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.xrecyclerview.XRecyclerView;
import com.example.xrecyclerview.refresh.SwipyRefreshLayout;
import com.example.xrecyclerview.refresh.SwipyRefreshLayoutDirection;
import com.jess.arms.base.BaseHolder;
import com.jess.arms.base.DefaultAdapter;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.utils.DoubleClickUtils;

import java.util.ArrayList;
import java.util.List;

import me.jessyan.mvparms.demo.R;

/**
 * @author DrChen
 * @Date 2019/2/26 0026.
 * qq:1414355045
 *  我的优惠券
 */
public class StoreVpAdapter extends PagerAdapter{

    private List<String> list = new ArrayList<>();
    private LayoutInflater inflater;
    private List<Boolean> booleanList;
    private Context context;

    private VpAdapterListener<Boolean> listener;

    public void setListener(VpAdapterListener<Boolean> listener) {
        this.listener = listener;
    }

    public StoreVpAdapter( List<String> list, Context context) {

        this.list = list;
       this. context = context;
        inflater = LayoutInflater.from(context);

       booleanList = new ArrayList<>();
        booleanList.add(true);
        booleanList.add(false);
        booleanList.add(true);
        booleanList.add(true);
        booleanList.add(true);
        booleanList.add(false);
        booleanList.add(true);
        booleanList.add(true);
        booleanList.add(true);
        booleanList.add(true);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view ==object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view;
        if(position==0){//商家
            view = inflater.inflate(R.layout.vp_store_detail,null);
            bindStoreView(view);
        }else {//领券
            view = inflater.inflate(R.layout.vp_store_coupon_list,null);
            bindView(view,booleanList);
        }


        container.addView(view,0);
        return  view;
    }

    /**
     *
     *  商家详情
     */
    private void bindStoreView(View view) {
    }


    /**
     *
     * @param view
     * @param t
     *  领券
     */
    private void bindView(View view, List<Boolean> t ) {
        SwipyRefreshLayout refreshLayout = view.findViewById(R.id.refresh);
        XRecyclerView recyclerView = view.findViewById(R.id.recyclerView);


        //刷新，发起网络请求
        refreshLayout.setOnRefreshListener(new SwipyRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh(SwipyRefreshLayoutDirection direction) {

            }
        });



        recyclerView.setPullRefreshEnabled(false);
        recyclerView.clearHeader();

        LinearLayoutManager lr = new LinearLayoutManager(context,LinearLayoutManager.VERTICAL,false);
        recyclerView .setLayoutManager(lr);
        ArmsUtils.configRecyclerView(recyclerView,lr);
        DefaultAdapter adapter = new DefaultAdapter(t,true) {
            @Override
            public BaseHolder getHolder(View v, int viewType) {
                return new BaseHolder<Boolean>(v) {
                    @Override
                    public void setData(Boolean data, int pos) {

                    }
                };
            }

            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_coupon_fuck;
            }


        };
        recyclerView.setAdapter(adapter);

        recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() { }

            @Override
            public void onLoadMore() {

            }
        });

adapter.setOnItemClickListener(new DefaultAdapter.OnRecyclerViewItemClickListener<Boolean>() {
    @Override
    public void onItemClick(View view, int viewType, Boolean data, int pos) {
        if(DoubleClickUtils.getInstance().isDouble(view)){
            return;
        }



    }
});

    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
            container.removeView((View) object);
    }

    public  interface  VpAdapterListener<T> {
        void getItem(View view, int type, T data);
    }


}
